package com.mpsc.seata.provite.controller;

import com.mpsc.api.bean.UserInfoEntity;
import com.mpsc.seata.provite.service.UserInfoService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userInfo")
@Api(value = "UserInfoController", tags = "用户管理")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/user")
    @ApiOperation("保存用户信息")
    public void saveUserInfo(@RequestBody UserInfoEntity user) {
        userInfoService.saveUserInfo(user);
    }

    @PostMapping("/update/user")
    @ApiOperation("保存用户信息")
    //@GlobalTransactional(name = "my_test_tx_group",rollbackFor = Exception.class)
    public void updateUserInfo(@RequestBody UserInfoEntity user) {
        userInfoService.updateUserInfo(user);
    }

    @GetMapping("/find/user")
    @ApiOperation("查询用户信息")
    @GlobalTransactional(name = "my_test_tx_group",rollbackFor = Exception.class)
    public String findUserInfo() {
        userInfoService.findUserById(1L);
        return "测试成功！！！！";
    }
}
